package com.baitengsoft.patentapimonitor.api.controller;

import com.baitengsoft.patentapimonitor.api.entity.WebUserinfoEntity;
import com.baitengsoft.patentapimonitor.api.model.RptPatentDataAreaInfo;
import com.baitengsoft.patentapimonitor.api.service.RptPatentDataAreaService;
import com.baitengsoft.patentapimonitor.common.utils.Res;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 专利创造指标分析
 * @author Chen 2017/12/25
 */
@RestController
@RequestMapping("/api/v1/web/statistic")
@Api(value = "前台-专利创造指标分析",description = "专利创造指标分析")
public class WebRptPatentDataAreaController extends AbstractController {
    @Autowired
    private RptPatentDataAreaService rptPatentDataAreaService;

    /**
     * 有效发明，获取指定平台下区域的有效发明数据
     */
    @ApiOperation(value = "有效发明/year 1-今年，0-去年")
    @GetMapping("/validipat/{year}")
    public Res getValidIPatList(@PathVariable(value = "year") Integer year){
        if (year ==null){
            year = 0;
        }
        if (year !=1 && year!=0){
            return Res.error("请求参数有误");
        }
        WebUserinfoEntity userInfo = getUserInfo();
        if (userInfo ==null || userInfo.getPlatformid()==null){
            return Res.error("登录信息失效");
        }
        List<RptPatentDataAreaInfo> infos = rptPatentDataAreaService.getValidIPatListByYear(userInfo.getPlatformid(), year);
        return Res.ok().put("infos",infos);
    }

    /**
     * 万人有效发明专利拥有量，获取指定平台下区域的当前万人有效发明专利拥有量
     */
    @ApiOperation(value = "万人有效发明专利拥有量/year 1-今年，0-去年")
    @GetMapping("/millionipat/{year}")
    public Res getMillionIPatList(@PathVariable(value = "year") Integer year){
        if (year ==null){
            year = 0;
        }
        if (year !=1 && year!=0){
            return Res.error("请求参数有误");
        }
        WebUserinfoEntity userInfo = getUserInfo();
        if (userInfo ==null || userInfo.getPlatformid()==null){
            return Res.error("登录信息失效");
        }
        List<RptPatentDataAreaInfo> infos = rptPatentDataAreaService.getMillionIPatByYear(userInfo.getPlatformid(), year);
        return Res.ok().put("infos",infos);
    }

    /**
     * 专利申请
     */
    @ApiOperation(value = "专利申请/year 1-今年，0-去年")
    @GetMapping("/patapply/{year}")
    public Res getPatApplyList(@PathVariable(value = "year") Integer year){
        if (year ==null){
            year = 0;
        }
        if (year !=1 && year!=0){
            return Res.error("请求参数有误");
        }
        WebUserinfoEntity userInfo = getUserInfo();
        if (userInfo ==null || userInfo.getPlatformid()==null){
            return Res.error("登录信息失效");
        }
        List<RptPatentDataAreaInfo> infos = rptPatentDataAreaService.getPatApplyByYear(userInfo.getPlatformid(), year);
        return Res.ok().put("infos",infos);
    }

    /**
     * 发明专利申请
     */
    @ApiOperation(value = "发明专利申请/year 1-今年，0-去年")
    @GetMapping("/ipatapply/{year}")
    public Res getIpatApplyList(@PathVariable(value = "year") Integer year){
        if (year ==null){
            year = 0;
        }
        if (year !=1 && year!=0){
            return Res.error("请求参数有误");
        }
        WebUserinfoEntity userInfo = getUserInfo();
        if (userInfo ==null || userInfo.getPlatformid()==null){
            return Res.error("登录信息失效");
        }
        List<RptPatentDataAreaInfo> infos = rptPatentDataAreaService.getIpatApplyByYear(userInfo.getPlatformid(), year);
        return Res.ok().put("infos",infos);
    }

    /**
     * 专利授权
     */
    @ApiOperation(value = "专利授权/year 1-今年，0-去年")
    @GetMapping("/patauthorize/{year}")
    public Res getPatAuthorizeList(@PathVariable(value = "year") Integer year){
        if (year ==null){
            year = 0;
        }
        if (year !=1 && year!=0){
            return Res.error("请求参数有误");
        }
        WebUserinfoEntity userInfo = getUserInfo();
        if (userInfo ==null || userInfo.getPlatformid()==null){
            return Res.error("登录信息失效");
        }
        List<RptPatentDataAreaInfo> infos = rptPatentDataAreaService.getPatAuthorizeByYear(userInfo.getPlatformid(), year);
        return Res.ok().put("infos",infos);
    }

    /**
     * 万人专利授权
     */
    @ApiOperation(value = "万人专利授权/year 1-今年，0-去年")
    @GetMapping("/wrpatauthorize/{year}")
    public Res getWRPatAuthorizeList(@PathVariable(value = "year") Integer year){
        if (year ==null){
            year = 0;
        }
        if (year !=1 && year!=0){
            return Res.error("请求参数有误");
        }
        WebUserinfoEntity userInfo = getUserInfo();
        if (userInfo ==null || userInfo.getPlatformid()==null){
            return Res.error("登录信息失效");
        }
        List<RptPatentDataAreaInfo> infos = rptPatentDataAreaService.getWRPatAuthorizeByYear(userInfo.getPlatformid(), year);
        return Res.ok().put("infos",infos);
    }

    /**
     * 发明专利授权
     */
    @ApiOperation(value = "发明专利授权/year 1-今年，0-去年")
    @GetMapping("/ipatauthorize/{year}")
    public Res getIpatAuthorizeList(@PathVariable(value = "year") Integer year){
        if (year ==null){
            year = 0;
        }
        if (year !=1 && year!=0){
            return Res.error("请求参数有误");
        }
        WebUserinfoEntity userInfo = getUserInfo();
        if (userInfo ==null || userInfo.getPlatformid()==null){
            return Res.error("登录信息失效");
        }
        List<RptPatentDataAreaInfo> infos = rptPatentDataAreaService.getIpatAuthorizeByYear(userInfo.getPlatformid(), year);
        return Res.ok().put("infos",infos);
    }

    /**
     * 发明专利授权
     */
    @ApiOperation(value = "万人发明专利授权/year 1-今年，0-去年")
    @GetMapping("/wripatauthorize/{year}")
    public Res getWRIpatAuthorizeList(@PathVariable(value = "year") Integer year){
        if (year ==null){
            year = 0;
        }
        if (year !=1 && year!=0){
            return Res.error("请求参数有误");
        }
        WebUserinfoEntity userInfo = getUserInfo();
        if (userInfo ==null || userInfo.getPlatformid()==null){
            return Res.error("登录信息失效");
        }
        List<RptPatentDataAreaInfo> infos = rptPatentDataAreaService.getWRIpatAuthorizeByYear(userInfo.getPlatformid(), year);
        return Res.ok().put("infos",infos);
    }

    /**
     * 有效专利
     */
    @ApiOperation(value = "有效专利/year 1-今年，0-去年")
    @GetMapping("/yxpatent/{year}")
    public Res getYXPatentList(@PathVariable(value = "year") Integer year){
        if (year ==null){
            year = 0;
        }
        if (year !=1 && year!=0){
            return Res.error("请求参数有误");
        }
        WebUserinfoEntity userInfo = getUserInfo();
        if (userInfo ==null || userInfo.getPlatformid()==null){
            return Res.error("登录信息失效");
        }
        List<RptPatentDataAreaInfo> infos = rptPatentDataAreaService.getYXPatentByYear(userInfo.getPlatformid(), year);
        return Res.ok().put("infos",infos);
    }

    /**
     * 万人有效专利拥有量
     */
    @ApiOperation(value = "万人有效专利拥有量/year 1-今年，0-去年")
    @GetMapping("/wryxpatent/{year}")
    public Res getWRYXPatentList(@PathVariable(value = "year") Integer year){
        if (year ==null){
            year = 0;
        }
        if (year !=1 && year!=0){
            return Res.error("请求参数有误");
        }
        WebUserinfoEntity userInfo = getUserInfo();
        if (userInfo ==null || userInfo.getPlatformid()==null){
            return Res.error("登录信息失效");
        }
        List<RptPatentDataAreaInfo> infos = rptPatentDataAreaService.getWRYXPatentByYear(userInfo.getPlatformid(), year);
        return Res.ok().put("infos",infos);
    }

    /**
     * 实质审查
     */
    @ApiOperation(value = "实质审查/year 1-今年，0-去年")
    @GetMapping("/szsc/{year}")
    public Res getSZSCList(@PathVariable(value = "year") Integer year){
        if (year ==null){
            year = 0;
        }
        if (year !=1 && year!=0){
            return Res.error("请求参数有误");
        }
        WebUserinfoEntity userInfo = getUserInfo();
        if (userInfo ==null || userInfo.getPlatformid()==null){
            return Res.error("登录信息失效");
        }
        List<RptPatentDataAreaInfo> infos = rptPatentDataAreaService.getSZSCByYear(userInfo.getPlatformid(), year);
        return Res.ok().put("infos",infos);
    }

}
